package cmbchina.util.db;

import cmbchina.util.AppConfig;

import java.sql.*;
import java.util.Properties;

public class DBHelper {
//    public static final String url = "jdbc:mysql://99.12.156.27:3306/flowable?characterEncoding=UTF-8";
    public static Properties appConfig = AppConfig.getInstance().getConfig();
    public static final String flowable_url = appConfig.getProperty("flowable_url");
    public static final String flowable_driver = appConfig.getProperty("flowable_driver");
    public static final String flowable_user = appConfig.getProperty("flowable_user");
    public static final String flowable_password = appConfig.getProperty("flowable_password");

    public Connection conn = null;
    public PreparedStatement pst = null;

    static {
        try {
            Class.forName(flowable_driver); //classLoader,加载对应驱动
            System.out.println("==="+flowable_driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public Connection getConn() {
        Connection conn = null;
        try {

            conn = (Connection) DriverManager.getConnection(flowable_url, flowable_user, flowable_password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public void close(Connection conn,PreparedStatement ps,ResultSet rs) {
        try {

            if(conn!=null){
                conn.close();

            }
            if(ps!=null){
                ps.close();
            }
            if(rs!=null){
                rs.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}